package com.weixin.xplore.dao.service.impl;

import com.weixin.xplore.dao.common.BaseRepository;
import com.weixin.xplore.dao.entity.IntegralRecord;
import com.weixin.xplore.dao.service.IntegralRecordDaoService;
import lombok.RequiredArgsConstructor;
import org.anyline.adapter.KeyAdapter;
import org.anyline.entity.DataRow;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;


@Service
@RequiredArgsConstructor
public class IntegralRecordDaoServiceImpl extends BaseRepository<IntegralRecord> implements IntegralRecordDaoService {
    @Override
    public Boolean saveLog(String userId, Integer integralType, Long integralNum) {
        return this.saveLog(userId, integralType, integralNum, "default");
    }

    @Override
    public Boolean saveLog(String userId, Integer integralType, Long integralNum, String source) {
        IntegralRecord integralRecord = new IntegralRecord();
        integralRecord.setUserId(userId);
        integralRecord.setIntegralType(integralType);
        integralRecord.setIntegralNum(new BigDecimal(integralNum));
        integralRecord.setSource(source);

        return super.saveDataRow(DataRow.build(KeyAdapter.KEY_CASE.CAMEL_LOWER, integralRecord));
    }
}
